import request from '../utils/request'
//查询某个用户购物车中所有的记录
export const getCartList=()=>{
  return request.get('/cart');
}
//添加购物车记录
export const addCart=(data:any)=>{
  return request.post('/cart', data)
}

//添加秒杀商品到购物车
export const addKillCart=(itemId: number, num: number = 1)=>{
  return request.post('/cart', {
    itemId,
    num,
    isKill: 1 // 标记为秒杀商品
  })
}
//更新购物车记录的购买数量
export const updateBuyCount=(cartId:number,num:number)=>{
  return request.put(`/cart/item?cartId=${encodeURIComponent(cartId)}&num=${encodeURIComponent(num)}`)
}
//删除购物车记录
export const deleteCart=(cartId:number)=>{
  return request.delete(`/cart/item/${cartId}`)
}
//获取某个用户购物车中的商品总数
export const getCartTotalCount=()=>{
  return request.get(`/cart/totalCount`)
}
//根据商品名称模糊查询购物车记录
export const getCartByName=(keyword:string)=>{
return request.get(`/cart/search?keyword=${encodeURIComponent(keyword)}`)
}

//购物车结算接口
export const checkoutCart=(orderNo:string)=>{
const BigOrderNo=BigInt(orderNo)
return request.post('/alipay/chargePayItem', null,{params:BigOrderNo})
}
//添加购物车订单
export const addCartOrder=(ids: number[], addressId: number)=>{
  return request.post('/itemOrder/addCartOrder', ids, {
    params: { addressId }
  })
}

// 余额支付
export const payOrder = (orderNo: string | number) => {
  console.log('支付API被调用，订单号:', orderNo, '类型:', typeof orderNo)
  return request.post('/payOrder/pay', null, {
    params: { OrderNo: orderNo }
  })
}
